//  CurrentServiceVC.m
//  XJMTechnician
//  Created by Mr.hu on 2017/11/12.
//  Copyright © 2017年 Mr.hu. All rights reserved.

#import "CurrentServiceVC.h"
#import "FirstCurrent_ServiceCell.h"
#import "SecondCurrent_ServiceCell.h"
#import "ThreeCurrent_ServiceCell.h"

@interface CurrentServiceVC ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *TableView_CurrentService;
/** 注释 **/
@property (strong, nonatomic) NSArray * leftImage;
/** 注释 **/
@property (strong, nonatomic) NSArray * leftname;

/** 注释 **/
@property (strong, nonatomic) NSArray * leftdetail;
@property (nonatomic,strong)  NSDictionary * ServiceDict;

@end

@implementation CurrentServiceVC

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [self requestCurrentOrder];
}

- (void)requestCurrentOrder{
    
    [XJHttpClass OrderDetailOrder_id:self.CurrentOrder_ID token:[XJToolClass getToken] andFinishblock:^(id response, NSString *errStr) {
        if (errStr) {
            [XJToolClass tipAnimationWith:errStr];
        }else{
            self.ServiceDict = response[@"data"];
            
            if ([XJToolClass changeType:self.ServiceDict]) {
            self.leftdetail = @[self.ServiceDict[@"nickname"],self.ServiceDict[@"address"],self.ServiceDict[@"user_note"],self.ServiceDict[@"goods_name"],self.ServiceDict[@"server_time"]];
            [self.TableView_CurrentService reloadData];
                
            }
        }
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addLeftBtn:[UIImage imageNamed:@"fanhui"] Action:@selector(backToRootView)];
    self.title = @"当前订单";
    
    [self requestCurrentRequest];
    self.leftImage = @[@"账户",@"地址",@"留言",@"按摩",@"时间"];
    self.leftname = @[@"客户信息",@"服务地址",@"客户留言",@"服务项目",@"服务时长"];
    
}

- (void)requestCurrentRequest{

    self.TableView_CurrentService.delegate = self;
    self.TableView_CurrentService.dataSource = self;
    self.TableView_CurrentService.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.TableView_CurrentService registerNib:[UINib nibWithNibName:@"FirstCurrent_ServiceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FirstCurrent_ServiceCell"];
    
    [self.TableView_CurrentService registerNib:[UINib nibWithNibName:@"SecondCurrent_ServiceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SecondCurrent_ServiceCell"];
    [self.TableView_CurrentService registerNib:[UINib nibWithNibName:@"ThreeCurrent_ServiceCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ThreeCurrent_ServiceCell"];
}

#pragma mark - TableViewDatasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row == 0) {
        FirstCurrent_ServiceCell * firstServiec = [tableView dequeueReusableCellWithIdentifier:@"FirstCurrent_ServiceCell" forIndexPath:indexPath];
        return firstServiec;
        
    }else if (indexPath.row == 6){
        
        ThreeCurrent_ServiceCell * ThreeCurrent =[tableView dequeueReusableCellWithIdentifier:@"ThreeCurrent_ServiceCell" forIndexPath:indexPath];
        ThreeCurrent.CurrentService_SOS.layer.cornerRadius = 50;
        ThreeCurrent.CurrentService_SOS.layer.masksToBounds = YES;
        ThreeCurrent.CurrentService_SOS.layer.borderColor  = [UIColor colorWithRed:(243)/255.0 green:(32)/255.0 blue:(32)/255.0 alpha:(1)].CGColor;
        ThreeCurrent.CurrentService_SOS.layer.borderWidth = 1;
        ThreeCurrent.CurrentService_SOS.enabled = NO;
        [ThreeCurrent.CurrentService_SOS addTarget:self action:@selector(SOSMethOnclicked) forControlEvents:UIControlEventTouchUpInside];
        
        return ThreeCurrent;
        
    }else if(indexPath.row == 5){
        
        SecondCurrent_ServiceCell * Secondfriend=[tableView dequeueReusableCellWithIdentifier:@"SecondCurrent_ServiceCell" forIndexPath:indexPath];
        [Secondfriend.Service_leftimage setImage:[UIImage imageNamed:self.leftImage[indexPath.row-1]]];
        Secondfriend.Service_leftName.text = [NSString stringWithFormat:@"%@ :",self.leftname[indexPath.row-1]];
        Secondfriend.Service_detaillab.text = [NSString stringWithFormat:@"%@分钟",self.leftdetail[indexPath.row-1]];
        return Secondfriend;
        
    }else{
        SecondCurrent_ServiceCell * Secondfriend=[tableView dequeueReusableCellWithIdentifier:@"SecondCurrent_ServiceCell" forIndexPath:indexPath];
        [Secondfriend.Service_leftimage setImage:[UIImage imageNamed:self.leftImage[indexPath.row-1]]];
        Secondfriend.Service_leftName.text = [NSString stringWithFormat:@"%@ :",self.leftname[indexPath.row-1]];
        
        Secondfriend.Service_detaillab.text = self.leftdetail[indexPath.row-1];
        
        return Secondfriend;
    }
}

- (void)SOSMethOnclicked{

    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",@"110"];
    CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue];
    if (version >= 10.0) {
        /// 大于等于10.0系统使用此openURL方法
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 6) {
        [self SOSMethOnclicked];
    }
}

#pragma mark TableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        
        return 100;
        
    }else if (indexPath.row == 6){
        
        if ([[XJToolClass iphoneType] isEqualToString:@"5s"]) {
            return ScreenHeight-100-250;
        }else{
            return ScreenHeight-100-250;
        }
        
        
    }else{
        return 50;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}

@end
